/*
 * This servlet prepares the questions asked in the chat for the teacher
 */
package controllers.classes;

import classes.HibernateUtil;
import dao.ChatDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import models.Chat;

/**
 *
 * @author Achie
 */
public class QuestionReceiveController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        long lessonid = Long.parseLong(request.getParameter("lessonid"));
        HibernateUtil hu = new HibernateUtil();
        ChatDao cd = new ChatDao(hu.openSession());
        List<Chat> questionList = cd.findAllByLesson(lessonid, "question"); //chat objects of questions

        //set attributes
        request.setAttribute("lessonid", lessonid); //lessonid
        request.setAttribute("questionlist", questionList); //questions

        hu.close(); //close connection
        
        //send request attributes to the question window jsp
        RequestDispatcher dispatcher = request.getRequestDispatcher("jsp/question_window.jsp");
        dispatcher.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
